package org.ns.framework.datasource.mybatis;

import java.util.HashSet;
import java.util.Set;

public class CommitResult {

    Set<String> fails = new HashSet<>();

    public void addFailDataSource(String dataSourceName) {
        fails.add(dataSourceName);
    }

    public Set<String> getFailDataSources() {
        return fails;
    }

    public boolean commitOK() {
        return fails.size() == 0;
    }

    public void throwCommitException() {
        throw new CommitException(this);
    }

    public class CommitException extends RuntimeException{
        CommitResult commitResult;

        public CommitException(CommitResult commitResult) {
            this.commitResult = commitResult;
        }

        public CommitResult getCommitResult() {
            return commitResult;
        }
    }
}
